<?php
ArrowController::importModel("smarty.SmartyCompiler");
class ArrowMapTreeNode extends ArrowTagContainer{
	
	private $imagePath;
	
	public function configure(){
		$this->addProperties(array(
			"name" => null,
			"field" => null, //rowExtensionTemplate, searchTemplate
			"value" => null,
			"image" => null,
			"editable" => true,
			"editDialogSize" => "400|400",
			"editTemplate" => null,
			"addTemplate" => null,
			"addDialogSize" => "400|400",
			"maxChildren" => -1,
			"validChildren" => -1,
			"deletable" => true,
			
		));
		//$this->setRequiredParent("image");
		
		$this->setContentCodeKept(true);
		$this->setDisplay(false);
	}
	
	public function init(){
		$this->imagePath = ArrowController::$activeProject->getResources()->getResource($this->getProperty("image"))->getRelativePath(); 
	}
	
	public function getImagePath(){
		return $this->imagePath;
	}
	
	public function generateOutputCode(){
		return;
	}
	
	public function generateJsOptions(){
		$arr = array();
		
		$arr["max_children"] =  $this->getProperty("maxChildren");
		$children = $this->getProperty("validChildren");
		$arr["valid_children"] = explode(';', $children);
		$path  = $this->getProperty("editTemplate");
		if($path)
			$arr["edit_template"] =  ArrowTemplateLinker::getDefault()->generateTemplateLink( array( "path" => $path, "id" => "#key#", "_htmlAmp"=>"0" ) );
		elseif($path === "")
			$arr["edit_template"] = "";
		else
			$arr["edit_template"] = null;
			
		$path  = $this->getProperty("addTemplate");
		if($path)
			$arr["add_template"] =  ArrowTemplateLinker::getDefault()->generateTemplateLink( array( "path" => $path, "parent_id" => "#key#", "_htmlAmp"=>"0" ) );
		elseif($path === "")
			$arr["add_template"] = "";
		else
			$arr["add_template"] = null;			
			
		$arr["edit_dialog_size"] =  $this->getProperty("editDialogSize");
		$arr["add_dialog_size"] =  $this->getProperty("addDialogSize");
		
		if($this->getProperty("image"))
			$arr["icon"] = array( "image" => $this->getImagePath() );
		return $arr;
	}

}
?>
